Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


Extending the example to create and display records

This chapter concludes with a comprehensive example of using dynamic queries, buffers, temp-tables, and browses. The final example is saved as h-testDynTT.p.

To extend the current example to get some data into the temp-table and display it:

  1. Add a HANDLE variable for a dynamic query and some variables to display data in:
  2. /* Procedure h-testDynTT.p -- test dynamic temp-table 
       methods. */ 
    DEFINE VARIABLE hTT    AS HANDLE     NO-UNDO. 
    DEFINE VARIABLE hTTBuf AS HANDLE     NO-UNDO. 
    DEFINE VARIABLE hQuery AS HANDLE     NO-UNDO. 
    DEFINE VARIABLE iSeq  AS INTEGER    NO-UNDO INIT 1000. 
    DEFINE VARIABLE cName  LIKE Customer.NAME       NO-UNDO. 
    DEFINE VARIABLE iCNum  LIKE Customer.CustNum    NO-UNDO. 
    DEFINE VARIABLE cRep   LIKE SalesRep.RepName    NO-UNDO. 
    

  3. After the TEMP-TABLE-PREPARE method, capture the DEFAULT-BUFFER-HANDLE in a variable:
  4. hTT:TEMP-TABLE-PREPARE("CustSequence"). 
    hTTBuf = hTT:DEFAULT-BUFFER-HANDLE. 
    

  5. Define a static FOR EACH block to populate the temp-table with Customer and SalesRep values for Customers in New Hampshire, as well as a unique sequence value:
  6. /* Populate the temp-table with values from the database. */ 
    FOR EACH Customer WHERE State = "NH", SalesRep OF Customer: 
        hTTBuf:BUFFER-CREATE(). 
        hTTBuf:BUFFER-COPY(BUFFER Customer:HANDLE). 
        hTTBuf:BUFFER-COPY(BUFFER SalesRep:HANDLE). 
        hTTBuf:BUFFER-FIELD("Sequence"):BUFFER-VALUE = iSeq. 
        iSeq = iSeq + 1. 
    END. 
    

  7. Create a dynamic query for the temp-table buffer, prepare it to iterate through all the records in the temp-table, and open it:
  8. /* Now create a query for the temp-table buffer and display values. */ 
    CREATE QUERY hQuery. 
    hQuery:SET-BUFFERS(hTTBuf). 
    hQuery:QUERY-PREPARE("FOR EACH CustSequence"). 
    hQuery:QUERY-OPEN(). 
    hQuery:GET-FIRST(). 
    

  9. Walk through the query’s result list and copy some fields from the temp-table into the variables you defined. Display the values in a frame:
  10. REPEAT WHILE NOT hQuery:QUERY-OFF-END: 
        ASSIGN iSeq  = hTTBuf:BUFFER-FIELD("Sequence"):BUFFER-VALUE 
               cName = hTTBuf:BUFFER-FIELD("Name"):BUFFER-VALUE 
               iCNum = hTTBuf:BUFFER-FIELD("CustNum"):BUFFER-VALUE 
               cRep  = hTTBuf:BUFFER-FIELD("RepName"):BUFFER-VALUE. 
        DISPLAY iSeq FORMAT "9999" LABEL "Sequence" 
                iCNum  
                cName FORMAT "X(20)" 
                cRep FORMAT "X(20)" WITH FRAME CustSeqFrame 12 DOWN. 
        hQuery:GET-NEXT(). 
    END. 
    

    In a more general-purpose procedure, you could create dynamic fill-ins for each of the fields you want to display and capture their format, label, and other attributes from the buffer fields of the temp-table.

  11. Run the procedure:
  12. The primary index for the temp-table is the Sequence index, so the records come back in that order.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095